package com.example.wangbo.widgettest_417wb;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView tv;
    private EditText et;
    private Button btngettext,btnsetimg;
    private ImageView iv;
    private ImageButton ibtn;
    private RadioGroup rg;
    private RadioButton rbnan,rbnv;
    private CheckBox cblan,cbzu,cbyou;
    private Button btngetgender,btngetfun;

    private String strfun="";


    public MainActivity() {
    }


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        tv=(TextView) findViewById(R.id.textView);
        et=(EditText) findViewById(R.id.editText);
        btngettext=(Button) findViewById(R.id.button);
        btnsetimg=(Button)findViewById(R.id.button2);
        iv=(ImageView)  findViewById(R.id.imageView);
        ibtn=(ImageButton) findViewById(R.id.imageButton);

        rg=(RadioGroup)findViewById(R.id.radioGroup);
        rbnan=(RadioButton)findViewById(R.id.radioButton4);
        rbnv=(RadioButton)findViewById(R.id.radioButton3) ;
        cblan=(CheckBox)findViewById(R.id.eckBox4);
        cbzu=(CheckBox)findViewById(R.id.eckBox3);
        cbyou=(CheckBox)findViewById(R.id.eckBox2);
        btngetgender=(Button)findViewById(R.id.tton4);
        btngetfun=(Button)findViewById(R.id.tton5);
//设置按钮监听器
        btngetgender.setOnClickListener(this);
        btngetfun.setOnClickListener(this);
        btngettext.setOnClickListener(this);
        btnsetimg.setOnClickListener(this);
        ibtn.setOnClickListener(this);

        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            public void onCheckedChanged(RadioGroup radioGroup,
                                         @IdRes int i) {
                switch(i)
                {
                    case R.id.radioButton3:
                        tv.setText("女");
                        break;
                    case R.id.radioButton4:
                        tv.setText("男");
                        break;
                }
            }
        });
        cblan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b)
                    strfun+="篮球+";
                else
                    strfun=strfun.replace("篮球+","");
                tv.setText(strfun);
            }
        });
        cbzu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b)
                    strfun+="足球+";
                else
                    strfun=strfun.replace("足球+","");
                tv.setText(strfun);
            }
        });
        cbyou.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b)
                    strfun+="游泳+";
                else
                    strfun=strfun.replace("游泳+","");
                tv.setText(strfun);
            }
        });

    }


    public void onClick(View v) {
        switch(v.getId())
        {
            case R.id.button:
                String str=et.getText().toString();
                tv.setText(str);
                break;
            case R.id.button2:
                iv.setImageResource(R.drawable.b);
                break;
            case R.id.imageButton:
                break;
            case R.id.tton4:
                if(rbnan.isChecked())   tv.setText("男");
                if(rbnv.isChecked())   tv.setText("女");
                break;
            case R.id.tton5:
                String msg="";
                if(cblan.isChecked()) msg+="篮球+";
                if(cbzu.isChecked()) msg+="足球+";
                if(cbyou.isChecked()) msg+="游泳";
                tv.setText(msg);
                break;
        }
    }
}
